package com.waypolice.manager.controller;

import com.waypolice.manager.service.BorRegisterService;
import com.waypolice.manager.service.BorMyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 描述:
 *
 * @author zyp
 * @description 借阅登记action
 * @create 2019-03-12 9:51
 */
@Controller
@Api(value = "借阅登记控制器", description = "借阅登记")
@RequestMapping(value="/pcwindow")
public class BorrowRegisterAction {

    private static final Logger logger = LoggerFactory.getLogger(BorrowRegisterAction.class);

    @Autowired
    private BorRegisterService borRegisterService;

    @Autowired
    private BorMyService borMyService;


    /**
     * @author:zyp
     * @description 借阅登记首页跳转
     * @date: 2019/3/12 15:53
     * @return 
     */
    @ApiOperation(value = "借阅登记首页跳转")
    @RequestMapping(value = "/toBorrowRegister")
    public String toBorrowRegister(){
        return "/borrowManager/borrowRegister";
    }

    /**
     * @author:zyp
     * @description 获取借阅登记内容
     * @date: 2019/3/12 16:06
     * @return 
     */
    @ApiOperation(value = "借阅登记首页数据加载")
    @RequestMapping(value = "/getBorRegiser")
    @ResponseBody
    public Object getRegisterList(@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                                  @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                                  @RequestParam(required = false, defaultValue = "", value = "search") String search,
                                  @RequestParam(required = false, value = "sort") String sort,
                                  @RequestParam(required = false, value = "order") String order,String fileType){
        //先将线下借阅的未在指定时间求取的文档置为已失效
//        borRegisterService.updateBorStatusTo2();
        //将线上的借阅归还时间已到的文档置为已归还
//        borMyService.updateBorStatusUP(null);
        Map<String, Object> result = borRegisterService.getRegisterList(offset, limit,search, sort, order, fileType);
        return result ;
    }

    /**
     * @author:zyp
     * @description 借阅记录的审核信息数据加载
     * @date: 2019/3/12 17:34
     * @return 
     */
    @ApiOperation(value = "借阅记录的审核信息数据加载")
    @RequestMapping(value = "/approvalInfoList")
    @ResponseBody
    public Object getApprovalInfoList(@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                                      @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                                      @RequestParam(required = false, value = "sort") String sort,
                                      @RequestParam(required = false, value = "order") String order,Long id){
        Map<String, Object> result = borRegisterService.getApprovalInfo(offset, limit, sort, order, id);
        return result;
    }

    /**
     * @author:zyp
     * @description 授权检索记录
     * @date: 2019/3/29 11:08
     * @return 
     */
    @ApiOperation(value = "授权检索记录")
    @RequestMapping(value = "/accreditSearchRegiser")
    @ResponseBody
    public Object accreditSearchRegiser(String fileIds,String registerIds ){
        Object result = borRegisterService.accreditSearchRegiser(fileIds, registerIds);
        return result;
    }

}